package com.xiaoze.databaseTableControl.service.impl;

import java.util.List;
import java.util.UUID;

import com.xiaoze.common.utils.DateUtils;
import com.xiaoze.common.utils.SecurityUtils;
import com.xiaoze.databaseTableControl.domain.DatabseTableSql;
import com.xiaoze.databaseTableControl.mapper.DatabseTableSqlMapper;
import com.xiaoze.databaseTableControl.service.IDatabseTableSqlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


/**
 * 用户提交的sql记录Service业务层处理
 *
 * @author hhz
 * @date 2024-12-16
 */
@Service
public class DatabseTableSqlServiceImpl extends ServiceImpl<DatabseTableSqlMapper, DatabseTableSql> implements IDatabseTableSqlService {
    @Autowired
    private DatabseTableSqlMapper databseTableSqlMapper;

    /**
     * 查询用户提交的sql记录
     *
     * @param id 用户提交的sql记录ID
     * @return 用户提交的sql记录
     */
    @Override
    public DatabseTableSql selectDatabseTableSqlById(Long id) {
        return databseTableSqlMapper.selectDatabseTableSqlById(id);
    }

    /**
     * 查询用户提交的sql记录列表
     *
     * @param databseTableSql 用户提交的sql记录
     * @return 用户提交的sql记录
     */
    @Override
    public List<DatabseTableSql> selectDatabseTableSqlList(DatabseTableSql databseTableSql) {
        return databseTableSqlMapper.selectDatabseTableSqlList(databseTableSql);
    }

    /**
     * 新增用户提交的sql记录
     *
     * @param databseTableSql 用户提交的sql记录
     * @return 结果
     */
    @Override
    public int insertDatabseTableSql(DatabseTableSql databseTableSql) {
        // databseTableSql.setBatchId(UUID.randomUUID().toString().replace("-", "")); // 设置批次号
        // databseTableSql.setSubUser(SecurityUtils.getUsername()); // 记录当前登录用户
        databseTableSql.setCreateTime(DateUtils.getNowDate());
        return databseTableSqlMapper.insertDatabseTableSql(databseTableSql);
    }

    /**
     * 修改用户提交的sql记录
     *
     * @param databseTableSql 用户提交的sql记录
     * @return 结果
     */
    @Override
    public int updateDatabseTableSql(DatabseTableSql databseTableSql) {
        databseTableSql.setUpdateTime(DateUtils.getNowDate());
        return databseTableSqlMapper.updateDatabseTableSql(databseTableSql);
    }

    /**
     * 批量删除用户提交的sql记录
     *
     * @param ids 需要删除的用户提交的sql记录ID
     * @return 结果
     */
    @Override
    public int deleteDatabseTableSqlByIds(Long[] ids) {
        return databseTableSqlMapper.deleteDatabseTableSqlByIds(ids);
    }

    /**
     * 删除用户提交的sql记录信息
     *
     * @param id 用户提交的sql记录ID
     * @return 结果
     */
    @Override
    public int deleteDatabseTableSqlById(Long id) {
        return databseTableSqlMapper.deleteDatabseTableSqlById(id);
    }
}
